package com.cndatacom.eweb.service.impl;

import java.util.List;

import com.cndatacom.eweb.common.PaginationModel;
import com.cndatacom.eweb.dao.IUserDao;
import com.cndatacom.eweb.model.User;
import com.cndatacom.eweb.model.UserOrganization;
import com.cndatacom.eweb.model.UserRole;
import com.cndatacom.eweb.service.IUserService;

@SuppressWarnings("unchecked")
public class UserService implements IUserService {

	private IUserDao userDao;
	
	public User getUserById(int userId) {
		return userDao.getUserById(userId);
	}

	public User loginValid(String username, String password) {
		return userDao.getUserByUsernameAndPassword(username, password);
	}

	public boolean validateUsername(String account) {
		User user = userDao.getUserByUsername(account);
		if(user != null) {
			return true;
		}
		return false;
	}

	public User addOrEditUser(User user) {
		userDao.saveOrUpateUser(user);
		return user;
	}

	public boolean delUser(User user) {
		userDao.delUser(user);
		return true;
	}

	public PaginationModel getAllUser(int offset, int pageSize) {
		return userDao.getAllUser(offset, pageSize);
	}
	
	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public boolean addOrEditUserRole(int userId, int roleId) {
		return userDao.addOrUpdateUserRole(userId, roleId);
	}

	public boolean deleteUserRole(int userId, int roleId) {
		return userDao.deleteUserRole(userId, roleId);
	}

	public PaginationModel getAllUserRoles(int userId, int offset, int pageSize) {
		return userDao.getAllUserRoles(userId, offset, pageSize);
	}

	public UserRole getUserRoleByUseridAndRoleid(int userId, int roleId) {
		return userDao.getUserRoleByUseridAndRoleid(userId, roleId);
	}

	public boolean addOrUpdateUserOrganization(int userId, int organizationId) {
		return userDao.addOrUpdateUserOrganization(userId, organizationId);
	}

	public boolean deleteUserOrganization(int userId, int organizationId) {
		return userDao.deleteUserOrganization(userId, organizationId);
	}

	public PaginationModel getAllUserOrganizations(int userId, int offset, int pageSize) {
		return userDao.getAllUserOrganizations(userId, offset, pageSize);
	}

	public UserOrganization getUserOrganizationByUseridAndOrganizationid(int userId, int organizationId) {
		return userDao.getUserOrganizationByUseridAndOrganizationid(userId, organizationId);
	}

	public List getAllUserOrganizations(int userId) {
		return userDao.getAllUserOrganizations(userId);
	}

	public List getAllUserRoles(int userId) {
		return userDao.getAllUserRoles(userId);
	}

}
